package com.readygo.boot_test.entity.auth;

import org.springframework.security.core.GrantedAuthority;

import javax.persistence.*;

@Entity
public class Role implements GrantedAuthority {

    private static final long serialVersionUID = -3343375181378553608L;

    @EmbeddedId
    private RoleKey roleKey;

    @PrePersist
    private void prePersist() {
        if (getRoleKey() == null) {
            RoleKey roleKey = new RoleKey();
            roleKey.setRole("");
            roleKey.setSecurityUserId(0);
            setRoleKey(roleKey);
        }
    }

    public RoleKey getRoleKey() {
        return roleKey;
    }

    public void setRoleKey(RoleKey roleKey) {
        this.roleKey = roleKey;
    }

    @Override
    public String getAuthority() {
        return roleKey.getRole();
    }


}
